package org.chengn.level_middle.context2779;

/**
 * @author GengMY
 * @date 2024/6/15
 * @Description
 */
public class Context2779 {
    public int maximumBeauty(int[] nums, int k) {
        int len = nums.length;
        int[] ans = new int[200002];
        for (int i = 0; i < len; ++i) {
            ans[Math.max(0, nums[i] - k)] ++;
            ans[Math.min(200001, nums[i] + k) + 1] --;
        }

        int res = 0, sum = 0;
        for (int i = 0; i < ans.length; ++i) {
            sum += ans[i];
            res = Math.max(res, sum);
        }

        return res;
    }
}
